package testjava.grammar;

import java.util.Random;

public class Operator {

    /**
     * @param args
     */
    /**
     * @param args
     */
    public static void main(String[] args) {
        // testBitOperation();
        // testByteArrayToHexString();
        // System.out.println(Integer.toBinaryString((1 << 2) | 0x02));
        // String str = "";
        // System.out.println(str.getClass() == String.class);
    }

    private static void testByteArrayToHexString() {
        byte[] bs = new byte[3];
        new Random().nextBytes(bs);
        for (int i = 0; i < bs.length; i++) {
            bs[0] = 0;
            System.out.println(bs[i]);
            System.out.println(Integer.toHexString(bs[i]));
            System.out.println(Integer.toHexString(bs[i] & 0xFF));
            String str = Integer.toHexString(bs[i] & 0xFF);
            if (str.length() == 1)
                str += "0";
            System.out.println(str);
            System.out.println("*************************");
        }
    }

    private static void testBitOperation() {

        int b = 3;
        int c = 5;
        System.out.println(Integer.toBinaryString(b));
        System.out.println(Integer.toBinaryString(c));
        System.out.println(b | c);
        System.out.println(b & c);
        System.out.println(~b);
        System.out.println(b ^ c);
        // testShift();
    }

    private static void testShift() {
        int a = 1;
        for (int i = 0; i < 8; i++) {
            a <<= 1;
            System.out.println(Integer.toBinaryString(a));
            System.out.println(a);
        }

        int b = 23;
        for (int i = 0; i < 5; i++) {
            b >>= 1;
            System.out.println(Integer.toBinaryString(b));
            System.out.println(b);
        }
    }

}
